//
//  PLEndpoint.h
//  Plankton    
//
//  Created by Marc Schlichte on 2008-05-03.
//  Copyright 2008-2009 Framework Labs. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol PLEndpointDelegate;

/// This is the abstraction used by PLPlatform to send and receive data blobs
/// using the socket datagram model. No guarantees are made about delivery and ordering.
///
@interface PLEndpoint : NSObject 
{
@private
    CFSocketRef             sock;
    unsigned short          port;
    id<PLEndpointDelegate>  delegate;
}

@property(nonatomic, assign)   id<PLEndpointDelegate>  delegate;	//!< the delegate to inform about data reception and errors
@property(nonatomic, readonly) NSString                *host;		//!< the host as dotted ip-address
@property(nonatomic, readonly) unsigned short          port;		//!< the port number of this endpoint

//! sends the given data blob to the specified host (given as dotted ip-address) and port
- (void)sendData:(NSData *)data toHost:(NSString *)host port:(unsigned short)port;

@end

/// The delegate endpoints use to indicate data reception and errors
///
@protocol PLEndpointDelegate <NSObject>
@optional
- (void)endpoint:(PLEndpoint *)endpoint didReceiveData:(NSData *)data from:(NSData *)addr;
- (void)endpoint:(PLEndpoint *)endpoint didEncounterProblem:(NSString *)problem;

@end

